Inside Macintosh: QuickTime Components

Previous | Chapter Top | Chapter Contents | Next

Handling Movie Events

Movie controller components provide functions that handle movie controller actions. Your application must call these functions whenever an event occurs. Consider this event loop:

#if whatIsHandleEvent
    while (! gDoneFlag) {
        gResult = GetNextEvent (everyEvent, &gEventRec);
        if (( MCIsPlayerEvent(gMCPlay, &gEventRec) == 0 )) {
            if (gResult) {
                /* player didn't handle the event */
                HandleEvent(gEventRec);
            }
        }
    }
#endif
#if 0
/* interface for application-defined routine: */
pascal Boolean MyPlayerFilter ( MovieController mc,
                                            short* action, long* params);
#endif

If the movie controller component handles the event, your application can loop to wait for the next event. Otherwise, your application must take care of the event as part of its normal event handling.

Movie controller components support an action filter. You can instruct the filter to invoke a function in your application whenever actions occur. This action filter function can then perform specialized processing or refer the action back to the movie controller component. The actions supported by movie controller components are discussed in "Movie Controller Actions," which begins on Movie Controller Actions .

The MCIsPlayerEvent function lets you pass events to a movie controller component. The MCSetActionFilterWithRefCon function allows you to specify your action filter function for a movie controller.

You can use the MCDoAction function to request action processing from a movie controller.

If you use any Movie Toolbox functions to change the characteristics of a movie that is associated with a movie controller, you must inform the movie controller--use the MCMovieChanged function.

You can obtain information about the current state of the movie controller and its movie by calling the MCGetControllerInfo function.

MCIsPlayerEvent

The MCIsPlayerEvent function handles all events for a movie controller. Your application should call this function in its main event loop. Call MCIsPlayerEvent for each active movie controller until the event is handled.

This function returns a long integer indicating whether the movie controller component handled the event. The component sets this long integer to 1 if it handled the event. Your application should then skip the rest of its event loop and wait for the next event. The return value is 0 otherwise. Your application must then handle the event as part of its normal event processing.

The movie controller component does everything necessary to support the movie controller and its associated movie. For example, the component calls the Movie Toolbox's MoviesTask function for each movie. The movie controller component also handles suspend and resume events. It treats suspend events as deactivate requests and resume events as activate requests.

You can provide an action filter function that is called by the movie controller component. See "Application-Defined Function," which begins on Application-Defined Function , for details. The component calls your filter function after it decides to process a particular action, but before it actually does so. In this manner, your application can perform custom action processing for a movie controller. Set your action filter function with the MCSetActionFilterWithRefCon function, described on MCSetActionFilterWithRefCon .

pascal ComponentResult MCIsPlayerEvent (MovieController mc,
                                          const EventRecord *e);
mc
Specifies the movie controller for the operation. You obtain this identifier from the Component Manager's OpenComponent or OpenDefaultComponent function, or from the NewMovieController function (described on NewMovieController ).
e
Points to the current event structure.

DESCRIPTION

The MCIsPlayerEvent function returns a long integer indicating whether it handled the event. If the movie controller component handled the event, this function sets the returned value to 1. Your application should then skip the rest of its event loop and wait for the next event. If the component did not handle the event, the MCIsPlayerEvent function returns a value of 0. Your application must then handle the event.

MCDoAction

Your application can use the MCDoAction function to invoke a movie controller component and have it perform a specified action.

pascal ComponentResult MCDoAction (MovieController mc,
                                         short action, void *params);
mc
Specifies the movie controller for the operation. You obtain this identifier from the Component Manager's OpenComponent or OpenDefaultComponent function, or from the NewMovieController function.
action
Specifies the action to be taken. See "Movie Controller Actions," which begins on Movie Controller Actions , for descriptions of the actions supported by movie controller components.
params
Points to the parameter data appropriate to the action. See the individual action descriptions in "Movie Controller Actions," which begins on Movie Controller Actions , for information about the parameters required for each supported action.

DESCRIPTION

For example, your application might define a menu item that stops all currently playing movies. When the user selects this menu item, your application could use the MCDoAction function to instruct each controller to stop playing. You would do so by specifying an mcActionPlay action with the parameters set to 0 to indicate that the controller should stop playing the movie.

MCSetActionFilterWithRefCon

The MCSetActionFilterWithRefCon function allows your application to establish an action filter function for a movie controller. The movie controller component calls your action filter function each time the component receives an action for its movie controller. Your filter function is then free to handle the action or to refer it back to the movie controller component. If you refer it back to the movie controller component, the component handles the action. See "Movie Controller Actions," which begins on Movie Controller Actions , for a description of the actions supported by movie controller components.

pascal ComponentResult MCSetActionFilterWithRefCon
                                         (MovieController mc,
                                          MCActionFilterWithRefConUPP blob,
                                          long refCon);
mc
Specifies the movie controller for the operation. You obtain this identifier from the Component Manager's OpenComponent or OpenDefaultComponent function, or from the NewMovieController function (described on NewMovieController ).
blob
Points to your action filter function. Set this parameter to nil to remove your action filter function.
refCon
Contains a reference constant value. The movie controller component passes this reference constant to your action filter function each time it calls your function.

DESCRIPTION

Movie controller components allow your application to field movie controller actions. You define an action filter function in your application and assign it to a controller by calling the MCSetActionFilterWithRefCon function.

You can use the constants described in "Movie Controller Actions," which begins on Movie Controller Actions , to refer to movie controller actions.

If your filter function handles an action, you can handle the action in any way you desire. For example, your filter function could change the operation of movie controller buttons. More commonly, applications use the action filter function to monitor actions of the controller. For instance, your filter function might enable you to find out when the user clicks the play button, so that your application can enable appropriate menu selections. Alternatively, you can use the filter function to detect when the user resizes the movie.

SEE ALSO

If you use any Movie Toolbox functions that modify the movie in your action filter function, be sure to call the MCMovieChanged function (described on MCMovieChanged ).

MCGetControllerInfo

Your application can use the MCGetControllerInfo function to determine the current status of a movie controller and its associated movie. You can use this information to control your application's menu highlighting.

pascal ComponentResult MCGetControllerInfo (MovieController mc,
                                          long *someFlags);
mc
Specifies the movie controller for the operation. You obtain this identifier from the Component Manager's OpenComponent or OpenDefaultComponent function, or from the NewMovieController function (described on NewMovieController ).
someFlags
Contains a pointer to flags that specify the current status and capabilities of the controller. The following flags are defined (more than one flag may be set to 1):
mcInfoUndoAvailable
The user has edited the movie. If this flag is set to 1, you can call the MCUndo function (described on MCUndo ).
mcInfoCutAvailable
The user has selected some material in the movie and editing is enabled. If this flag is set to 1, you can call the MCCut function (described on MCCut ).
mcInfoCopyAvailable
The user has selected some material in the movie. If this flag is set to 1, you can call the MCCopy function (described on MCCopy ).
mcInfoPasteAvailable
There is movie data in the scrap and editing is enabled. If this flag is set to 1, you can call the MCPaste function (described on MCPaste ).
If your application maintains a private scrap, this flag does not reflect the state of that scrap.
mcInfoClearAvailable
The user has selected some material in the movie and editing is enabled. If this flag is set to 1, you can call the MCClear function (described on MCClear ).
mcInfoHasSound
The movie has sound. If this flag is set to 1, the controller can play a movie's sound.
mcInfoIsPlaying
If this flag is set to 1, the movie is playing.
mcInfoIsLooping
The controller is currently set to play its movie repeatedly. If this flag is set to 1, the movie is looping.
mcInfoIsInPalindrome
The controller is currently set to play its movie repeatedly, alternating between forward and backward playback. If this flag is set to 1, the movie is in palindrome looping mode.
mcInfoEditingEnabled
The user can edit the movie associated with this controller. If this flag is set to 1, you have enabled editing by calling the MCEnableEditing function (described on MCEnableEditing ).

MCMovieChanged

The MCMovieChanged function lets you inform a movie controller component that your application has used the Movie Toolbox to change the characteristics of its associated movie.

pascal ComponentResult MCMovieChanged (MovieController mc,
                                         Movie m);
mc
Specifies the movie controller for the operation. You obtain this identifier from the Component Manager's OpenComponent or OpenDefaultComponent function, or from the NewMovieController function (described on NewMovieController ).
m
Identifies the movie that has been changed.

DESCRIPTION

Your application should be able to make most movie changes using the MCDoAction function (described on MCDoAction ). However, if your application uses Movie Toolbox functions to change the characteristics of a movie that is associated with a movie controller, you must inform the controller so that it can update itself accordingly. For instance, if your application changes the size of the movie without informing the movie controller component, the control portion of the controller may no longer be the proper size for the movie.

RESULT CODES

Memory Manager errors


© 1997 Apple Computer, Inc.

Previous | Chapter Top | Chapter Contents | Next